package com.bw.sparksql1.job1
import org.apache.log4j.{Level, Logger}
import org.apache.spark.sql.{DataFrame, SparkSession}
/**
  *
  */
object Job11 {
    def main(args: Array[String]): Unit = {
      Logger.getLogger("org").setLevel(Level.ERROR)
      val spark = SparkSession
        .builder()
        .master("local")
        .appName(this.getClass.getSimpleName)
        .getOrCreate()
      spark.udf.register("strLen",(str:String) =>{
        if(str != null){
          str.length
        }else{
          0
        }
      })
      val df: DataFrame = spark.read.load("users.parquet")
      df.createOrReplaceTempView("users")
      spark.sql("select strLen(name) from users").show()
    }
}